package handler

import (
	"github.com/gin-gonic/gin"
	"trpg-base/entity"
	"trpg-common/request"
	"trpg-common/response"
)

type CharacterHandler struct{}

func (handler CharacterHandler) InsertOrUpdateCharacter(c *gin.Context) {
	character := entity.Character{}
	request.GetStructFromGinContext(c, &character)
	user := request.GetUserFromGinContext(c)
	response.SuccessWithData(c, characterService.InsertOrUpdateCharacter(character, user))
}

func (handler CharacterHandler) UploadExcel(c *gin.Context) {
	id := request.GetIntFromPath(c, "id")
	file := request.GetFileFromForm(c, "excel")
	user := request.GetUserFromGinContext(c)
	characterService.UploadExcel(file, user, id)
	response.Success(c)
}

func (handler CharacterHandler) GetCharacterList(c *gin.Context) {
	user := request.GetUserFromGinContext(c)
	response.SuccessWithData(c, characterService.GetCharacters(user))
}

func (handler CharacterHandler) GetCharacterDetail(c *gin.Context) {
	id := request.GetIntFromPath(c, "id")
	response.SuccessWithData(c, characterService.GetCharacterDetail(id))
}
